package tool

func Merge(arr []int, l, mid, r int) {
	help := make([]int, r-l+1)

	i := 0
	p1 := l
	p2 := mid + 1

	for p1 <= mid && p2 <= r {
		if arr[p1] <= arr[p2] {
			help[i] = arr[p1]
			p1++
		} else if arr[p1] > arr[p2] {
			help[i] = arr[p2]
			p2++
		}
		i++

	}

	if p1 > mid {
		for p2 <= r {

			help[i] = arr[p2]
			p2++
			i++
		}
	}
	if p2 > r {
		for p1 <= mid {

			help[i] = arr[p1]
			p1++
			i++
		}
	}

	for i2, v := range help {
		arr[l+i2] = v
	}
}
